﻿#ifndef UIMODELMANAGE_H
#define UIMODELMANAGE_H

#include <QMap>
#include <QWidget>
#include <QFuture>
#include <QFutureWatcher>


#include <shlib/viewmodel/imodel.h>

#define TEST_MODEL_MANAGE 1
/*
描述：组态管理窗口，管理组态场景
*/
class UiModelManage: public QWidget
{
    Q_OBJECT
public:
    UiModelManage(QWidget* parent = nullptr);
    ~UiModelManage();

    /*
    描述：在界面上添加一个场景item
    参数：场景数据
    日期: 2024-01-24
    */
    void addSceneItem(QSharedPointer<IModel>& model);

    /*
    描述：在界面上删除一个场景item
    参数：场景id,场景名称
    日期: 2024-01-24
    */
    void removeSceneItem(QString name);

    /**
     * @brief 获取当前使用的模型对象
     *
     * @return class QStandardItemModel* 返回当前的模型对象指针
     */
    class QStandardItemModel *getModel() const;

    /**
     * @brief 设置模型对象
     *
     * @param model 指向新的模型对象的指针
     */
    void setModel(class QStandardItemModel *model);


private slots:
    void slotNewScene();                     //新建场景
    void slotRemoveScene(QString name);        //删除场景
    void slotEditScene(QString name);          //编辑场景
    void slotCopyScene(QString name);          //复制场景

    void importModel();


private:
    void initUi();
    void initData();

    void reloadAllModel();

protected:
    bool eventFilter(QObject *obj, QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;


private:
    class QVBoxLayout* m_mainLayout = nullptr;
    class QPushButton* m_newSceneBtn = nullptr;
    class QPushButton* m_importModelBtn = nullptr;
    class QPushButton* m_refreshSceneBtn = nullptr;
    class QListView* m_modelView = nullptr;
    class QStandardItemModel* m_model = nullptr;
    class UiModelManageDelegate* m_delegate = nullptr;

    QMap<QString,QSharedPointer<IModel>> m_modelDataMap;                    //id-组态数据映射
    //QMap<quint16,class UiConfigurationEditWindow*> m_sceneMap;    //id-组态窗口映射

};

#endif // UIMODELMANAGE_H
